﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using LDSP.BRL;
using System.Data;
using BYFW.SFL;

namespace LDSP.Helper
{
    public class CommonControlInitial
    {
        public static void InitialPageSize(DropDownList ddl_pagesiz)
        {
            ddl_pagesiz.Items.Clear();
            ddl_pagesiz.Items.Add(new ListItem("每页显示10条", "10"));
            ddl_pagesiz.Items.Add(new ListItem("每页显示20条", "20"));
            ddl_pagesiz.Items.Add(new ListItem("每页显示30条", "30"));
            try
            {
                ddl_pagesiz.SelectedIndex = 0;
            }
            catch { }
        }

        public static void InitialTaskStatus(DropDownList ddl_taskStatus)
        {
            ddl_taskStatus.Items.Clear();
            //ddl_taskStatus.Items.Add(new ListItem("未开始", TaskStatus.未开始.ToString())); 去掉了这个状态
            ddl_taskStatus.Items.Add(new ListItem("进行中", TaskStatus.进行中.ToString()));
            ddl_taskStatus.Items.Add(new ListItem("已完成", TaskStatus.已完成.ToString()));
            ddl_taskStatus.Items.Add(new ListItem("暂停", TaskStatus.暂停.ToString()));
            try
            {
                ddl_taskStatus.SelectedIndex = 0;
            }
            catch { }
        }

        public static void InitialSubdiary(DropDownList ddl_subdiary, List<Enterprise> subdiaryList)
        {
            ddl_subdiary.Items.Clear();
            ddl_subdiary.Items.Add(new ListItem("--请选择子公司--", "0"));

            foreach (Enterprise sub in subdiaryList)
            {
                ddl_subdiary.Items.Add(new ListItem(sub.Code, sub.ID.ToString()));
            }
            try
            {
                ddl_subdiary.SelectedIndex = 0;
            }
            catch { }
        }

        public static void InitialEnterpriseList(DropDownList ddl_enterprise, DataTable dt)
        {
            dt = CommonOP.SortedTable(dt, "code DESC");

            ddl_enterprise.Items.Clear();
            ddl_enterprise.Items.Add(new ListItem("--请选择企业--", "0"));
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Enterprise en = new Enterprise();
                en.GetProperties(dt.Rows[i]);

                ddl_enterprise.Items.Add(new ListItem(dt.Rows[i]["code"].ToString(), dt.Rows[i]["id"].ToString()));
            }
        }

        public static void InitialUserList(DropDownList ddl_user, List<EnterpriseUser> userList)
        {
            ddl_user.Items.Clear();
            ddl_user.Items.Add(new ListItem("--请选择用户--", "0"));

            if (userList.Count > 0)
            {
                foreach (EnterpriseUser user in userList)
                {
                    ddl_user.Items.Add(new ListItem(user.Code, user.ID.ToString()));
                }
            }
        }
    }
}